package com.boc.langxiang.presenter.shop;

import com.boc.langxiang.contract.shop.ProductDetailView;
import com.boc.langxiang.entity.request.ProductDetailRequest;
import com.boc.langxiang.entity.response.BaseResponse;
import com.boc.langxiang.entity.response.ProductDetailContent;
import com.boc.langxiang.net.HandleErrorSubscriber;

import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;

/**
 * Created by Li Guoxi on 2016/6/29.
 */
public class ProductDetailPresenter extends SuperPresenter {

    private ProductDetailView mView;

    public ProductDetailPresenter(ProductDetailView view) {
        super(view);
        this.mView = view;
    }

    public void getContent(String id) {
        final ProductDetailRequest request = new ProductDetailRequest();
        request.setId(id);
        mView.showLoading();
        mService.getProductDetail(request.params())
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .unsubscribeOn(Schedulers.io())
                .subscribe(new HandleErrorSubscriber<BaseResponse<ProductDetailContent>>(mView) {
                    @Override
                    public void onSuccess(BaseResponse<ProductDetailContent> response) {
                        mView.getDetailSuccess(response.getContent().getResult());
                    }
                });
    }
}
